/*
*	Developed by Leonardo Chatain and Pedro Dusso, at Universidade Federal do Rio Grande do Sul, Brasil, 2009/1
*	Source available at glpacman.codeplex.com
*/

#pragma once
#ifndef _GAME_H_
#define _GAME_H_

#include "Maze.h"
#include "Pacman.h"
#include "Phantom.h"
#include "Definitions.h"
#include <ctime>
#include <iostream>
#include "PerspectiveCamera.h"
#include <windows.h>
#include <mmsystem.h>
#include "gdiplus.h"


//#pragma comment(lib, "winmm32.lib")

class Game {
private:
	Maze maze;
	Pacman pac;
    //GLFont font;
	Phantom *phantoms;
	int nPhantoms;

	bool canWalk(Character *character);
	bool canMove(Character *character, Character::Directions dir);
	void phantomFunction();

	PerspectiveCamera fpCamera;
	PerspectiveCamera aboveCamera;
	PerspectiveCamera tpCamera;
	PerspectiveCamera *activeCamera;

	int currentCamera;

	bool paused;
	int level;

	void die();
	void restart();
	void gameOver();
	void victory();
	void killPhantonSounds(int phantonsAte);
	void drawMenu(void);
	void drawText(int x, int y, char* string);
	void resetAboveCamera();
	
	

public:
	Game(const char* path);
	~Game(void);

	// Updates the game state
	void update();
	void openMaze(const char* path);
	void draw();
	void keyDirection(Character::Directions direction);

	// Getters and setters
	inline Maze getMaze() { return maze; }
	inline Pacman getPacman() { return pac; }
	inline Phantom *getPhantoms() { return phantoms; }
	inline void setPacman(Pacman pacman) { pac = pacman; }
	inline void setIncomingPacDirection(Character::Directions dir) { pac.setIncomingDirection(dir); }
	inline PerspectiveCamera getActiveCamera() { return *activeCamera; }
	inline void setActiveCamera(int cam) {
		switch(cam) {
			case FPCAMERA:
				activeCamera = &fpCamera;
				currentCamera = FPCAMERA;
				break;
			case ABOVE_CAMERA:
				activeCamera = &aboveCamera;
				currentCamera = ABOVE_CAMERA;
				break;
			case TPCAMERA:
				activeCamera = &tpCamera;
				currentCamera = TPCAMERA;
		}
		//activeCamera->view();
	}
	inline void pause() { paused = true; }
	inline void unPause() { paused = false; }
	inline bool isPaused() { return paused; }

};

#endif